<template>
  <div :class="$store.getters.microGlobalParam.systemFlag === 'bpa' ? 'cdmc-width-class' : 'normal-width-class'">
    <div class="app-container" style="position:relative;">
      <el-tabs class="tl-tabs" ref="mytabs" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-model="activeTab" type="card" @tab-click="tabClick">
        <el-tab-pane label="我的反馈" name="myFeedback">
          <feedback-list ref="myFeedback" :refName="'myFeedback'"  :height="tableHeight" :feedbackState="1"></feedback-list>
        </el-tab-pane>
        <el-tab-pane label="反馈广场" name="allFeedback">
          <feedback-list ref="allFeedback" :refName="'allFeedback'" :height="tableHeight" :ispublic="1" :feedbackState="9"></feedback-list>
        </el-tab-pane>
        <el-tab-pane name="myApproval">
          <span slot="label"><el-badge :value="approvalCount" :max="99" :hidden="approvalCount === 0">我的待办</el-badge></span>
          <approval-index ref="myApproval" :refName="'myApproval'" :height="tableHeight" @approvalCount="getApprovalCount" :approvalState="1"></approval-index>
        </el-tab-pane>
        <el-tab-pane label="办理历史" name="feedbackHistory">
          <approval-index ref="feedbackHistory" :refName="'feedbackHistory'" :height="tableHeight" :feedbackState="9"></approval-index>
        </el-tab-pane>
        <el-tab-pane label="反馈列表" name="feedbackList" v-if="userRole.length > 0">
          <approval-index ref="feedbackList" :refName="'feedbackList'" :height="tableHeight"></approval-index>
        </el-tab-pane>
      </el-tabs>
      <el-button @click="openAddDialog" icon="el-icon-edit-outline" type="text" size="medium" style="position:absolute; right: 10px; top: 10px; z-index: 999">我要反馈</el-button>
      <add-feedback ref="addFeedback"  @refresh="doRefresh" ></add-feedback>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import feedbackList from './feedbackList'
import approvalIndex from '../mmsFeedbackApproval/approvalIndex'
import addFeedback from './addFeedback'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'uploadManage',
  mixins: [mixin_list],
  components: { feedbackList, approvalIndex, addFeedback },
  data() {
    return {
      activeTab: 'myFeedback',
      refListName: 'allFileList',
      queryParam: '',
      url: {
        queryCodeList: '/mms/suggestionFeedback/dataCodeList',
        queryUserRole: '/mms/suggestionFeedback/queryUserRole'
      },
      contactPerson: '',
      isQueryOnCreated: false,
      tableResizeRefs: [],
      approvalCount: 0,
      userRole: []
    }
  },
  methods: {
    // 查询当前用户角色
    queryUserRole() {
      getAction(this.url.queryUserRole, {})
        .then((res) => {
          if (res.success) {
            if (res.result) {
              this.userRole = res.result
              // 查询当前角色可以看到的内容
              this.$nextTick(() => {
                this.$refs.feedbackList.userRole = this.userRole
              })
            }
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
    },
    getApprovalCount(approvalCount) {
        this.approvalCount = approvalCount
    },
    doRefresh() {
      this.$refs.myFeedback.doQuery()
    },
    // 打开新增意见反馈页面
    openAddDialog() {
      this.$refs.addFeedback.isAdd = true
      this.$refs.addFeedback.visible = true
    },
    // 切换tab页签时
    tabClick(tab) {
      let tabName = tab.name
      if (tabName === 'myFeedback') {
        this.refListName = 'myFeedback'
        this.$refs[tabName].doQuery()
        this.$refs[tabName].reduceHeight = 200
      }
      if (tabName === 'allFeedback') {
        this.refListName = 'allFeedback'
        this.$refs[tabName].doQuery()
        this.$refs[tabName].reduceHeight = 200
      }
      if (tabName === 'myApproval') {
        this.refListName = 'myApproval'
        this.$refs[tabName].refListName = 'myApproval'
        this.$refs[tabName].doQuery()
        this.$refs[this.refListName].reduceHeight = 200
      }
      if (tabName === 'feedbackHistory') {
        this.refListName = 'feedbackHistory'
        this.$refs[tabName].refListName = 'feedbackHistory'
        this.$refs[tabName].doQuery()
        this.$refs[this.refListName].reduceHeight = 200
      }
      if (tabName === 'feedbackList') {
        this.refListName = 'feedbackList'
        this.$refs[tabName].refListName = 'feedbackList'
        this.$refs[tabName].doQuery()
        this.$refs[this.refListName].reduceHeight = 200
      }
      this.$nextTick(() => {
        this.$refs[tabName].resizeHandler()
      })
    }
  },
  created() {
    this.queryUserRole()
    this.$nextTick(() => {
      // 获取待办数量
      this.$refs['myApproval'].loadData().then(() => {
        this.approvalCount = this.$refs['myApproval'].pageInfo.totalCount
      })
    })
  }
}
</script>

<style scoped lang="scss">
 /deep/ .el-badge__content.is-fixed{
   position: absolute;
   top: 5px;
 }
.normal-width-class {
	padding: 0 17%
}
.cdmc-width-class {
 padding: 0 0
}
</style>
